package com.example.servicebind.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

public class DemoService extends Service {

    private static String strMsg = "this is a message from DemoService!";

    /**
     * 定义一个用于消息交互的binder对象
     */
    private MyBinder myBinder = new MyBinder();

    public class MyBinder extends Binder {

        /**
         * 对外提供访问service中数据的方法
         *
         * @return
         */
        public String getMsg() {
            return strMsg;
        }

    }

    @Override
    public void onCreate() {
        Log.i("DemoService", "onCreate");
        super.onCreate();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.i("DemoService", "onBind");
        return myBinder;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i("DemoService", "onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.i("DemoService", "onUnbind");
        return super.onUnbind(intent);
    }

    @Override
    public void onDestroy() {
        Log.i("DemoService", "onDestroy");
        super.onDestroy();
    }

}
